<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Registration component
 *
 * @package		Joomla
 * @subpackage	Registration
 * @since 1.0
 */
class JobBoardViewJAUserRegister extends JView
{
	function display($tpl = null)
	{
		if(!$this->getLayout() || $this->getLayout()=='default') $this->setLayout('regemployerform');
		global $mainframe;

		// Check if registration is allowed
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if (!$usersConfig->get( 'allowUserRegistration' )) {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}

		$pathway  =& $mainframe->getPathway();
		$document =& JFactory::getDocument();
		$params	= &$mainframe->getParams();
	 	
		$pathway->addItem( JText::_( 'New' ));

		// Load the form validation behavior
		JHTML::_('behavior.formvalidation');

		$user =& JFactory::getUser();
//		if (!$user->id)
//		{
//			$user->username = JRequest::getVar('username','');
//			$user->name = JRequest::getVar('name','');
//			$user->email = JRequest::getVar('email','');
//		}
//		$this->assignRef('user', $user);
		$this->assignRef('params',		$params);
		if (JRequest::getVar('layout')=='regjobseekerform'){
			$page_title = "Hồ sơ đăng ký tìm việc";
			if( setPageTitle(array("res_reg_title", "res_reg_keyword", "res_reg_description"), null, $page_title ) )
				$page_title = "";
			$this->jobseekerReg();
		}
		elseif (JRequest::getVar('layout')=='regemployerform'){			
		    $page_title = "Đăng ký tài khoản công ty";
			if( setPageTitle(array("emp_reg_title", "emp_reg_keyword", "emp_reg_description"), null, $page_title ) )
				$page_title = "";
			$this->employerReg();
		}
			
		
		// Page Title
		$menus	= &JSite::getMenu();
		$menu	= $menus->getActive();
		if( $page_title != "" ){
    		if (is_object( $menu )) {
    			$menu_params = new JParameter( $menu->params );
    			if (!$menu_params->get( 'page_title')) {
    				$params->set('page_title',	$page_title);
    			}
    		} else {
    			$params->set('page_title',	$page_title);
    		}
    		$document->setTitle( $params->get( 'page_title' ) );
		}		
		
		parent::display($tpl);
	}
			
	function employerReg()
	{
		
		$post = JRequest::get('request', JREQUEST_ALLOWRAW);
		require_once JPATH_COMPONENT_SITE.DS.'models'.DS.'japrofiles.php';
		$model_profile = new JobBoardModelJAProfiles();
		$item_profile = $model_profile->getItem();
		$item_profile->bind($post);
		$fieldList = getEditFieldList('ja_profiles');
		
		//GET TIMEZONE COMBO
		$user = JFactory::getUser();
		global $mainframe;
		$params = &$mainframe->getParams();
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		$check = $usersConfig->get('frontend_userparams');

		if ($check == '1' || $check == 1 || $check == NULL)
		{
				$params		= $user->getParameters(true);
		}
		
		$temp_child = null;
		$params->merge( $params );
		if($params->_xml){
			for ($i=0;$i<count($params->_xml['_default']->_children);$i++){
				if ($params->_xml['_default']->_children[$i]->_attributes['name']=='timezone'){
					$temp_child = $params->_xml['_default']->_children[$i];
				}
			}
			$params->_xml['_default']->_children = array();
			$params->_xml['_default']->_children[] = $temp_child;
		}
		//GET TIMEZONE COMBO
		
		$this->assignRef('params',$params);
		$this->assignRef('fieldlist', $fieldList);
		$this->assignRef('item_profile', $item_profile);
		
		
	}
	
	function jobseekerReg()
	{
		$post = JRequest::get('request', JREQUEST_ALLOWRAW);
		require_once JPATH_COMPONENT_SITE.DS.'models'.DS.'jaresumes.php';
		$model_resume = new JobBoardModelJAresumes();
		$item_resume = $model_resume->getItem();
		$item_resume->bind($post);
		$fieldList = getEditFieldList('ja_resumes');
				
		//GET TIMEZONE COMBO
		$user = JFactory::getUser();
		global $mainframe;
		$params = &$mainframe->getParams();
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		$check = $usersConfig->get('frontend_userparams');

		if ($check == '1' || $check == 1 || $check == NULL)
		{
				$params		= $user->getParameters(true);
		}
		$temp_child = null;
		$params->merge( $params );
		if($params->_xml){
			for ($i=0;$i<count($params->_xml['_default']->_children);$i++){
				if ($params->_xml['_default']->_children[$i]->_attributes['name']=='timezone'){
					$temp_child = $params->_xml['_default']->_children[$i];
				}
			}
			$params->_xml['_default']->_children = array();
			$params->_xml['_default']->_children[] = $temp_child;
		}
		
		//GET TIMEZONE COMBO
		
		$this->assignRef('fieldlist', $fieldList);
		$this->assignRef('item_resume', $item_resume);
	}
}
